﻿using CodeMonkey.Utils;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;

public class MyTestt : MonoBehaviour
{
    //Grid<HeatMapGridObject> g;

    Grid<StringGridObject> g2;

    //[SerializeField] HeatMeshVisual hm;

    //[SerializeField] HeatMeshBoolVisual hb;

    [SerializeField] HeatMapGridVisual hmv;

    [SerializeField] int width;
    [SerializeField] int height;
    [SerializeField] float cellSize;

    public Vector3 origion;
    void Start()
    {
        //g = new Grid<HeatMapGridObject>(width, height, cellSize, origion,(Grid<HeatMapGridObject> g,int x,int y)=>new HeatMapGridObject(x,y,g));
        //hmv = FindAnyObjectByType<HeatMapGridVisual>();
        //hmv.SetGird(g);

        g2 = new Grid<StringGridObject>(width, height, cellSize, origion, (Grid<StringGridObject> g, int x, int y) => new StringGridObject(x, y, g));



        //hm = FindAnyObjectByType<HeatMeshVisual>();

        //hb = FindAnyObjectByType<HeatMeshBoolVisual>();

        //hm.SetGird(g);

        //hb.SetGird(g);
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 cur = UtilsClass.GetMouseWorldPosition();

        if (Input.GetMouseButtonDown(0))
        {
            //Vector3 cur = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            //Vector3 cur = UtilsClass.GetMouseWorldPosition();
            //g.SetValue(cur, g.GetValue(cur) + 5);
            //g.AddValue(cur, 100, 2,10);
            //g.SetValue(cur, !g.GetValue(cur));

            //自定义热力图
            //HeatMapGridObject mapGridObject = g.GetValue(cur);
            //if (mapGridObject != null) 
            //{
            //    mapGridObject.AddValue(5);
            //}

        }
        else if (Input.GetMouseButtonDown(1))
        {
            Debug.Log(g2.GetGridObject(UtilsClass.GetMouseWorldPosition()));
        }

        //Vector3 cur = UtilsClass.GetMouseWorldPosition();
        //if (g.GetValue(cur) != -1)
        //{
        //    g.SetValue(cur, g.GetValue(cur) + 1);
        //}
    }
}


public class HeatMapGridObject
{
    int x;
    int y;
    int value;

    public const int HeapMapMaxValue = 100;
    public const int HeapMapMinValue = 0;

    Grid<HeatMapGridObject> g;

    public HeatMapGridObject(int x, int y, Grid<HeatMapGridObject> g)
    {
        this.x = x;
        this.y = y;
        this.g = g;
    }

    public void AddValue(int temp)
    {
        value += temp;
        value = Mathf.Clamp(value, HeapMapMinValue, HeapMapMaxValue);
        g.OnTriggerChange(x, y);
    }

    public float GetValueNormalize()
    {
        return (float)value / HeapMapMaxValue;
    }

    public override string ToString()
    {
        return value.ToString();
    }





}

public class StringGridObject
{
    int x;
    int y;
    string letter="";
    string number="";


    Grid<StringGridObject> g;

    public StringGridObject(int x, int y, Grid<StringGridObject> g)
    {
        this.x = x;
        this.y = y;
        this.g = g;
    }

    public void AddString(string temp)
    {
        letter += temp;
        g.OnTriggerChange(x, y);
    }

    public void AddNumber(string temp)
    { 
        number+= temp;
        g.OnTriggerChange(x, y);
    }


    public override string ToString()
    {
        return letter + '\n' + number;
    }





}
